﻿/// OpenGL程序框架

#include <GL/freeglut.h>

using namespace std;

GLint winWidth = 600, winHeight = 400;

static void init(void)
{
	glClearColor(1.0, 1.0, 1.0, 1.0);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	gluOrtho2D(0.0, winWidth, 0.0, winHeight);
}

static void display(void)
{
	glClear(GL_COLOR_BUFFER_BIT);
	
	glColor3f(0.0, 0.0, 0.0); // black

	// draw primitive
	glBegin(GL_LINES);
	glVertex2i(50, 50);
	glVertex2i(150, 150);
	glEnd();

	glFlush();
}

static void reshape(int w, int h)
{
	glClearColor(1.0, 1.0, 1.0, 1.0);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	gluOrtho2D(0.0, winWidth, 0.0, winHeight);
}

int main(int argc, char *argv[])
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_SINGLE | GLUT_SINGLE);
	glutInitWindowPosition(10, 50);
	glutInitWindowSize(winWidth, winHeight);
	glutCreateWindow("OpenGL Program Structure Demo");

	init();
	glutDisplayFunc(display);
	glutReshapeFunc(reshape);

	glutMainLoop();
	return 0;
}
